﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace Data.MappingClasses
{
    [TableAttribute(Name = "dbo.Payment")]
    public partial class Payment : AbstractMappingClass, INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private short _idPayment;

        private short _refStudent;

        private short _refMonth;

        private short _sum;

        private short _year;

        private EntityRef<Month> _Month;

        private EntityRef<Student> _Student;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(ChangeAction action);
        partial void OnCreated();
        partial void OnidPaymentChanging(short value);
        partial void OnidPaymentChanged();
        partial void OnrefStudentChanging(short value);
        partial void OnrefStudentChanged();
        partial void OnrefMonthChanging(short value);
        partial void OnrefMonthChanged();
        partial void OnyearChanging(short value);
        partial void OnyearChanged();
        #endregion

        public Payment()
        {
            this._Month = default(EntityRef<Month>);
            this._Student = default(EntityRef<Student>);
            OnCreated();
        }

        [ColumnAttribute(Storage = "_idPayment", AutoSync = AutoSync.OnInsert, DbType = "SmallInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public short idPayment
        {
            get
            {
                return this._idPayment;
            }
            set
            {
                if ((this._idPayment != value))
                {
                    this.OnidPaymentChanging(value);
                    this.SendPropertyChanging();
                    this._idPayment = value;
                    this.SendPropertyChanged("idPayment");
                    this.OnidPaymentChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_refStudent", DbType = "SmallInt NOT NULL")]
        public short refStudent
        {
            get
            {
                return this._refStudent;
            }
            set
            {
                if ((this._refStudent != value))
                {
                    if (this._Student.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnrefStudentChanging(value);
                    this.SendPropertyChanging();
                    this._refStudent = value;
                    this.SendPropertyChanged("refStudent");
                    this.OnrefStudentChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_refMonth", DbType = "SmallInt NOT NULL")]
        public short refMonth
        {
            get
            {
                return this._refMonth;
            }
            set
            {
                if ((this._refMonth != value))
                {
                    if (this._Month.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnrefMonthChanging(value);
                    this.SendPropertyChanging();
                    this._refMonth = value;
                    this.SendPropertyChanged("refMonth");
                    this.OnrefMonthChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_sum", DbType = "SmallInt NOT NULL")]
        public short sum
        {
            get { return _sum; }
            set
            {
                if (_sum != value)
                {
                    SendPropertyChanging();
                    _sum = value;
                    SendPropertyChanged("sum");
                }
            }
        }

        [ColumnAttribute(Storage = "_year", DbType = "SmallInt NOT NULL")]
        public short year
        {
            get
            {
                return this._year;
            }
            set
            {
                if ((this._year != value))
                {
                    this.OnyearChanging(value);
                    this.SendPropertyChanging();
                    this._year = value;
                    this.SendPropertyChanged("year");
                    this.OnyearChanged();
                }
            }
        }

        [AssociationAttribute(Name = "Month_Payment", Storage = "_Month", ThisKey = "refMonth", OtherKey = "idMonth", IsForeignKey = true)]
        public Month Month
        {
            get
            {
                return this._Month.Entity;
            }
            set
            {
                Month previousValue = this._Month.Entity;
                if (((previousValue != value)
                     || (this._Month.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Month.Entity = null;
                        previousValue.Payments.Remove(this);
                    }
                    this._Month.Entity = value;
                    if ((value != null))
                    {
                        value.Payments.Add(this);
                        this._refMonth = value.idMonth;
                    }
                    else
                    {
                        this._refMonth = default(short);
                    }
                    this.SendPropertyChanged("Month");
                }
            }
        }

        [AssociationAttribute(Name = "Student_Payment", Storage = "_Student", ThisKey = "refStudent", OtherKey = "idStudent", IsForeignKey = true)]
        public Student Student
        {
            get
            {
                return this._Student.Entity;
            }
            set
            {
                Student previousValue = this._Student.Entity;
                if (((previousValue != value)
                     || (this._Student.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Student.Entity = null;
                        previousValue.Payments.Remove(this);
                    }
                    this._Student.Entity = value;
                    if ((value != null))
                    {
                        value.Payments.Add(this);
                        this._refStudent = value.idStudent;
                    }
                    else
                    {
                        this._refStudent = default(short);
                    }
                    this.SendPropertyChanged("Student");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public override Model.ModelClasses.AbstractModel PureModel
        {
            get { return base.PureModel; }
            set { _pureModel = value; }
        }
    }
}